#include "GUINode.h"
#include <algorithm>
#include "Matrix.h"
#include "IRenderer.h"

HashedString GUINode::Type() const
{
	return HashedString("GUINode");
}

void GUINode::Enable()
{
	Maths::Matrix ortho(0, Renderer->getWindow()->Size().X, Renderer->getWindow()->Size().Y, 0, 0, 10);
	Renderer->PushProjectionMatrix(ortho);
	Renderer->PushModelViewMatrix(Maths::Matrix());
	
	for (IGUIElement::Vector_t::iterator it = m_elements.begin(), end = m_elements.end(); it != end; ++it)
		(*it)->Paint();
	
	Renderer->PopProjectionMatrix();
	Renderer->PopModelViewMatrix();

	INode::Enable();
}

void GUINode::Disable()
{
}

void GUINode::AddElement( Pointer<IGUIElement>& element )
{
	m_elements.push_back(element);
}

void GUINode::RemoveElement( Pointer<IGUIElement>& element )
{
	IGUIElement::Vector_t::iterator it = std::find(m_elements.begin(), m_elements.end(), element);
	m_elements.erase(it);
}